<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>学习成绩档案</title>
</head>
<body>
<div class="layuimini-container layuimini-page-anim">
  <div class="layuimini-main">

    <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    <script type="text/html" id="currentTableBar">
      <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">取消预约</a>
      <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="push">通知</a>
    </script>

  </div>
</div>
<script>
  layui.use(['form', 'table','miniPage','element'], function () {
    var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage;
    form.render();
    table.render({
      elem: '#currentTableId',
      url: '/adminOrderInfo',
      toolbar: '#toolbarDemo',
      defaultToolbar: ['filter', 'exports', 'print', {
        title: '提示',
        layEvent: 'LAYTABLE_TIPS',
        icon: 'layui-icon-tips'
      }],
      cols: [
        [
          {field: 'id', title: '预约单号', sort: true},
          {field: 'bookId', title: '登录号', sort: true},
          {field: 'bookName', title: '书名', sort: true},
          {field: 'borrowerId', title: '预约者编号', sort: true},
          {field: 'borrowerName',title: '预约者姓名', sort: true},
          {field: 'startDate', title: '预约时间', sort: true},
          {field: 'endDate', title: '预期归还时间', sort: true},
          {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
        ]
      ],
      limit: 15,
      page: true,
      skin: 'line'
    });


    /**
     * toolbar事件监听
     */
    table.on('toolbar(currentTableFilter)', function (obj) {
      if (obj.event === 'add') {   // 监听添加操作
        var content = miniPage.getHrefContent('teacher/addStudy.html');
        var index = layer.open({
          title: '添加学生',
          type: 1,
          shade: 0.2,
          maxmin:true,
          shadeClose: true,
          area: ['50%','50%'],
          content: content,
        });
        $(window).on("resize", function () {
          layer.full(index);
        });
      } else if (obj.event === 'delete') {  // 监听删除操作
        var checkStatus = table.checkStatus('currentTableId')
                , data = checkStatus.data;
        layer.alert(JSON.stringify(data));
      }
    });
    table.on('tool(currentTableFilter)', function (obj) {
      var data = obj.data;
      if (obj.event === 'delete') {
        layer.confirm('真的要取消预约么', function (index) {
          $.ajax({
            url: '/deleteOrder',
            type:'POST',
            data:{
              id:data.id
            },
            success:function (res){
              if(res.code==200){
                layer.close(index);
                layer.msg("删除成功!");
                parent.window.location.reload();
              }else {
                layer.msg(layer.msg(res.msg));
              }
            }

          })
        });
      }else if (obj.event === 'push') {
        layer.confirm('<div class="layui-inline">\n' +
                '      <label class="layui-form-label">验证密码</label>\n' +
                '      <div class="layui-input-inline">\n' +
                '        <input type="password" name="pwd" id="pwd" lay-verify="required" autocomplete="off" class="layui-input">\n' +
                '      </div>\n' +
                '    </div>', function (index) {
          $.ajax({
            url: '/pushOrder',
            type:'POST',
            data:{
              id:data.id,
              pwd:document.getElementById('pwd').value
            },
            success:function (res){
              if(res.code==200){
                layer.close(index);
                layer.msg("已发送通知邮件");
              }else {
                layer.msg(layer.msg(res.msg));
              }
            }

          })
          return false;
        });
        return false;
      }

  });
  });
</script>
</body>
</html>

